import request from '@/config/axios'
import { Sku, Spu } from '@/api/mall/product/spu'

export interface NChooseNActivityVO {
  id?: number
  name?: string
  picUrl?: string //活动主图

  salesChannel?: EmptyArrayType //销售渠道
  salesOnlineChannel?: EmptyArrayType //线上渠道
  price?: number //商品价格
  number?: number //选中N类
  discountScopes?: EmptyArrayType //N选N活动范围
  isUpdated: Boolean //是否允许修改
  startTime?: Date // 开始时间点
  endTime?: Date // 结束时间点
  remark?: string
  authorizedTenant?: EmptyArrayType //销售门店
  status?: number
  createTime?: Date
  startAndEndTime?: Date[]
  products?: DiscountProductVO[]
}
// 折扣相关 属性
export interface DiscountProductVO {
  spuId: number
  skuId: number
  discountPrice?: number
  discountPercent?: number
  activityProductLowPrice?: number
  discountType: number
  selected: boolean
  activityProductCount: number
}

// 扩展 Sku 配置
export type SkuExtension = Sku & {
  productConfig: DiscountProductVO
}

export interface SpuExtension extends Spu {
  skus: SkuExtension[] // 重写类型
}

// 查询N选N活动活动列表
export const getNChooseNActivityPage = async (params) => {
  return await request.get({ url: '/promotion/general-activity/page', params })
}

// 查询N选N活动活动详情
export const getNChooseNActivity = async (id: number) => {
  return await request.get({ url: '/promotion/general-activity/get?id=' + id })
}

// 新增N选N活动活动
export const createNChooseNActivity = async (data: NChooseNActivityVO) => {
  return await request.post({ url: '/promotion/general-activity/create', data })
}

// 修改N选N活动活动
export const updateNChooseNActivity = async (data: NChooseNActivityVO) => {
  return await request.put({ url: '/promotion/general-activity/update', data })
}

// 关闭N选N活动活动
export const closeNChooseNActivity = async (id: number) => {
  return await request.put({ url: '/promotion/general-activity/close?id=' + id })
}

// 删除N选N活动活动
export const deleteNChooseNActivity = async (id: number) => {
  return await request.delete({ url: '/promotion/general-activity/delete?id=' + id })
}
